package cn.panda.edu.controller;

import cn.panda.edu.model.Thesis;
import cn.panda.edu.service.ThesisService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * 类描述：  学生论文管理API
 * @author: DuanGaoXi
 * @date： 2018-01-17 上午8:57:17
 */
@RestController
@RequestMapping(value="/api/admin")
@Api(description="学生论文管理")
public class ManageThesisController {
	@Autowired
	private ThesisService thesisService;
	
	/**
	 * 
	* @Title: papermanageFy 
	* @Description: 分页模糊查询（学号+姓名）
	* @param @param studentId
	* @param @param studentName
	* @param @param pageIndex
	* @param @return  
	* @return PageInfo<Thesis>
	 */
	@ApiOperation(value="模糊查询论文",notes="模糊查询+分页")
	@RequestMapping(value = "/papermanageFy", method = RequestMethod.POST)
	@ApiImplicitParams({
						@ApiImplicitParam(name = "studentId", value = "学生ID", required = false, dataType = "int",paramType="form"),
						@ApiImplicitParam(name = "studentName", value = "学生姓名", required = false, dataType = "string",paramType="form"),
						@ApiImplicitParam(name = "pageIndex", value = "分页页数", required = true, dataType = "int",paramType="form")
})
	public Object papermanageFy(Integer studentId,String studentName,Integer pageIndex){
		PageInfo<Thesis> pThesis = thesisService.selectLikeByPageSelective(studentId, studentName, pageIndex, Constant.PAGE_SIZE);
		
		return ResultDataUtil.resData(200, "", pThesis);
	}
	
	/**
	 * 
	* @Title: papermanageDel 
	* @Description: 主键删除
	* @param @param thesisId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据主键删除论文",notes="主键删除")
	@RequestMapping(value = "/papermanageDel", method = RequestMethod.POST)
	@ApiImplicitParam(name = "thesisId", value = "论文ID", required = true, dataType = "int",paramType="form")
	public Map<String, Object> papermanageDel(Integer thesisId) {
		Map<String, Object> map = new HashMap<>();
		int result = thesisService.deleteByPrimaryKey(thesisId);
		if (result > 0) {
			map = ResultDataUtil.resData(200, "删除成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "删除失败",null) ;
		}
		return map;
	}
	
	/**
	 * 
	* @Title: papermanageAdd 
	* @Description: 动态添加论文信息
	* @param @param record
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="添加论文",notes="动态添加")
	@RequestMapping(value="/papermanageAdd", method = RequestMethod.POST)
	@ApiImplicitParam(name = "thesis", value = "论文对象", required = true, dataType = "object",paramType="form")
	public  Map<String, Object> papermanageAdd(Thesis record) {
		Map<String, Object> map = new HashMap<>();
		int result = thesisService.insert(record);
		if (result > 0) {
			map = ResultDataUtil.resData(200, "添加成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "添加失败",null) ;
		}
		return map;
	}

	
	/**
	 * 
	* @Title: papermanageDel 
	* @Description: 根据主键更新论文
	* @param @param record
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据主键更新论文",notes="有选择更新")
	@RequestMapping(value = "/papermanageUp", method = RequestMethod.POST)
	@ApiImplicitParam(name = "thesis", value = "论文对象", dataType = "object",paramType="form")
	public Map<String, Object> papermanageUp(Thesis record) {
		Map<String, Object> map = new HashMap<>();
		int result =  thesisService.updateByPrimaryKeySelective(record);
		if (result > 0) {
			map = ResultDataUtil.resData(200, "更新成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "更新失败",null) ;
		}
		return map;
	}
	
	
	/**
	 * 
	* @Title: papermanageSel 
	* @Description: 根据主键查询
	* @param @param thesisId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="id查询论文",notes="根据主键查询")
	@RequestMapping(value = "/papermanageSel", method = RequestMethod.POST)
	@ApiImplicitParam(name = "thesisId", value = "论文ID", required = true, dataType = "int",paramType="form")
	public Object papermanageSel(Integer thesisId) {
		Thesis thesis = thesisService.selectByPrimaryKey(thesisId);
		return ResultDataUtil.resData(200, "", thesis);
	}
	
}
